package cn.bby.tools.actions;

import cn.bby.tools.dialog.GenMockDataDialog;
import cn.bby.tools.service.StateManagementService;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiJavaFile;
import org.jetbrains.annotations.NotNull;

import static cn.bby.tools.utils.ClassDataMockUtil.PAST;

/**
 * 生成Mock数据的操作
 * 根据当前打开的实体类生成JSON格式的mock数据
 *
 * @author ben
 * @version 1.0
 */
public class GenMockDataAction extends AnAction {

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        Project project = e.getProject();
        if (project == null) {
            return;
        }

        // 获取当前编辑器
        Editor editor = e.getData(CommonDataKeys.EDITOR);

        // 显示生成Mock数据对话框
        GenMockDataDialog dialog = new GenMockDataDialog(project, editor);
        dialog.show();
    }

    @Override
    public void update(@NotNull AnActionEvent e) {
        if (e.getProject() == null
                || e.getData(CommonDataKeys.EDITOR) == null
                || !(e.getData(CommonDataKeys.PSI_FILE) instanceof PsiJavaFile)) {
            e.getPresentation().setVisible(false);
            return;
        }
    }

}